import 'dart:convert';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/screenutil.dart';
import 'package:mfkb/config/Config.dart';
import 'package:mfkb/pages/mine/About.dart';
import 'package:mfkb/pages/mine/MyDynamic.dart';
import 'package:mfkb/pages/mine/Opinion.dart';
import 'package:mfkb/pages/mine/Message.dart';
import 'package:mfkb/pages/mine/Setting.dart';
import 'package:mfkb/pages/modules/CustomRoute.dart';
import 'package:mfkb/pages/web/WebViewByUrl.dart';
import 'package:mfkb/plugin/MyBehavior.dart';

class Mine extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        width: ScreenUtil().setWidth(375) ,
        height:ScreenUtil().setHeight(812) ,
        color:Colors.white ,
        child: Column(
          children: <Widget>[
            Container(
              height: MediaQuery.of(context).padding.top ,
            ) ,
            Expanded(
              child: ScrollConfiguration(
                behavior: MyBehavior() ,
                child: ListView(
                  padding: EdgeInsets.only(top:0),
                  children: <Widget>[
                    GestureDetector(
                      child: Container(
                        color: Color.fromARGB(0, 0, 0, 0),
                        width:ScreenUtil().setWidth(375) ,
                        height:ScreenUtil().setHeight(60) ,
                        margin: EdgeInsets.fromLTRB(ScreenUtil().setWidth(23), ScreenUtil().setHeight(50), ScreenUtil().setWidth(15), 0),
                        child: Row(
                          children: <Widget>[
                            SizedBox(
                              width:ScreenUtil().setHeight(60) ,
                              height:ScreenUtil().setHeight(60) ,
                              child: CircleAvatar(
                                radius: 100.0 ,
                                backgroundColor: Colors.black,
                                backgroundImage:CachedNetworkImageProvider(
                                  Config().getHost()+jsonDecode(Config().getUserInfo())["icon"]
                                ) ,
                              ) ,
                            ) ,
                            Expanded(
                              child: GestureDetector(
                                child: Container(
                                  height:ScreenUtil().setHeight(60) ,
                                  margin: EdgeInsets.only(left:7 , right:13),
                                  child: Column(
                                    crossAxisAlignment: CrossAxisAlignment.start ,
                                    children: <Widget>[
                                      Container(
                                        height:ScreenUtil().setHeight(33) ,
                                        margin:EdgeInsets.only(top:ScreenUtil().setHeight(5)) ,
                                        child: Text(
                                          jsonDecode(Config().getUserInfo())["nickname"] ,
                                          overflow: TextOverflow.ellipsis ,
                                          style: TextStyle(
                                            fontSize: 23 ,
                                            fontFamily: "PingFangSC-Semibold,PingFang SC" ,
                                            height:1.2 ,
                                            fontWeight: FontWeight.w600 ,
                                            color: Color.fromARGB(255, 46, 52, 73)
                                          ),
                                        ),
                                      ) ,
                                      Container(
                                        height:ScreenUtil().setHeight(17) ,
                                        margin:EdgeInsets.only(top:ScreenUtil().setHeight(3)) ,
                                        child: Text(
                                          "请到个人中心修改个性签名" ,
                                          overflow: TextOverflow.ellipsis ,
                                          style: TextStyle(
                                            fontSize: 12 ,
                                            fontFamily: "Alibaba-PuHuiTi-R,Alibaba-PuHuiTi" ,
                                            height:1.1 ,
                                            fontWeight: FontWeight.normal ,
                                            color: Color.fromARGB(255, 138, 152, 173)
                                          ),
                                        ),
                                      )
                                    ],
                                  ),
                                ),
                              )
                            ) ,
                            Container(
                              width:ScreenUtil().setWidth(15) ,
                              height:ScreenUtil().setHeight(15) ,
                              child:Image.asset("assets/images/more_2x.png")
                            )
                          ],
                        ),
                      ),
                      onTap: (){
                        Navigator.of(context).push(CustomRoute(Setting())) ;
                      },
                    ) ,
                    Container(
                      width:ScreenUtil().setWidth(375) ,
                      height:ScreenUtil().setHeight(64) ,
                      margin: EdgeInsets.only(left:ScreenUtil().setWidth(25) , right:ScreenUtil().setWidth(25) , top:ScreenUtil().setHeight(36)),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceAround ,
                        children: <Widget>[
                          icon("assets/images/message.png" , "消息通知" , (){
                            Navigator.of(context).push(CustomRoute(Message())) ;
                          }) ,
                          icon("assets/images/dingdan1.png" , "我的订单" , (){

                          }) ,
                          icon("assets/images/fabu1.png" , "我的发布" , (){
                            Navigator.of(context).push(CustomRoute(MyDynamic())) ;
                          }) ,
                          icon("assets/images/kajuan1.png" , "我的卡卷" , (){

                          }) ,
                        ],
                      ),
                    ) ,
                    Container(
                      width:ScreenUtil().setWidth(375) ,
                      height:ScreenUtil().setHeight(360) ,
                      margin: EdgeInsets.only(top:ScreenUtil().setHeight(38)),
                      child: Column(
                        children: <Widget>[
                          item("assets/images/hhr.png" , "校园合伙人" , (){
                            Navigator.of(context).push(CustomRoute(WebViewByUrl(url: "https://unixbw.cn/hhr/",))) ;
                          }) ,
                          item("assets/images/opinion.png" , "意见反馈" , (){
                            Navigator.of(context).push(CustomRoute(Opinion())) ;
                          }) ,
                          // item("assets/images/fabu.png" , "我的发布" , (){
                            
                          // }) ,
                          // item("assets/images/kajuan.png" , "我的卡卷" , (){
                            
                          // }) ,
                          // item("assets/images/dingdan.png" , "我的订单" , (){
                            
                          // }) ,
                          item("assets/images/about.png" , "关于觅风" , (){
                            Navigator.of(context).push(CustomRoute(About())) ;
                          }) ,
                          item("assets/images/setting.png" , "设置" , (){
                            Navigator.of(context).push(CustomRoute(Setting())) ;
                          }) ,
                        ],
                      ),
                    )
                  ],
                ),
              )
            )
          ],
        )
      ),
    );
  }

  item(String image , String txt , var onClick){
    return GestureDetector(
      child: Container(
        height:ScreenUtil().setHeight(60) ,
        margin: EdgeInsets.only(left:ScreenUtil().setWidth(15) , right:ScreenUtil().setWidth(15)),
        color: Color.fromARGB(0, 0, 0, 0) ,
        child: Row(
          children: <Widget>[
            Container(
              width:ScreenUtil().setWidth(24) ,
              height:ScreenUtil().setWidth(24) ,
              child: Image.asset(image , fit: BoxFit.fill,),
            ) ,
            Expanded(
              child: Container(
                margin: EdgeInsets.only(left:ScreenUtil().setWidth(16)),
                child: Text(txt , style: TextStyle(
                  fontFamily: "PingFang-SC-Medium,PingFang-SC" ,
                  fontSize: 14 ,
                  fontWeight: FontWeight.w500 ,
                  color: Color.fromARGB(255, 78, 86, 108)
                ),),
              )
            ) ,
            Container(
              width:ScreenUtil().setWidth(16) ,
              height:ScreenUtil().setHeight(16) ,
              child: Image.asset("assets/images/more_2x.png"),
            )
          ],
        ),
      ) ,
      onTap: (){
        if(onClick != null){
          onClick() ;
        }
      }
    ) ;
  }

  icon(String image , String txt , var onClick){
    return Container(
      width:ScreenUtil().setWidth(60) ,
      height:ScreenUtil().setHeight(64) ,
      child:GestureDetector(
        child: Column(
          children: <Widget>[
            Container(
              width:ScreenUtil().setWidth(44) ,
              height:ScreenUtil().setHeight(44) ,
              margin: EdgeInsets.only(left:ScreenUtil().setWidth(2) , right:ScreenUtil().setWidth(2)),
              child:Image.asset(image) ,
            ) ,
            Container(
              width:ScreenUtil().setWidth(60) , 
              height:ScreenUtil().setHeight(20) ,
              child:Text(txt , style: TextStyle(
                fontSize: 12 ,
                color:Color.fromARGB(255, 78, 86, 108)
              ),textAlign: TextAlign.center,)  ,
            ) ,
          ],
        ),
        onTap: (){
          if(onClick != null) {
            onClick() ;
          }
        },
      )
    ) ;
  }
}